#include <bird.h>
#include<iostream>
Bird::Bird(int c)
{
    image.load(":/new/prefix1/flappybird/bird0_0.png");
    rect=image.rect();
    resetState();
    if(c==0)
    {   dirOfWing[0]=":/new/prefix1/flappybird/bird0_0.png";
        dirOfWing[1]=":/new/prefix1/flappybird/bird0_1.png";
        dirOfWing[2]=":/new/prefix1/flappybird/bird0_2.png";
    }
    if(c==1)
    {   dirOfWing[0]=":/new/prefix1/flappybird/bird1_0.png";
        dirOfWing[1]=":/new/prefix1/flappybird/bird1_1.png";
        dirOfWing[2]=":/new/prefix1/flappybird/bird1_2.png";
    }
    if(c==2)
    {   dirOfWing[0]=":/new/prefix1/flappybird/bird2_0.png";
        dirOfWing[1]=":/new/prefix1/flappybird/bird2_1.png";
        dirOfWing[2]=":/new/prefix1/flappybird/bird2_2.png";
    }

    curWing=0;
    timerId=startTimer(100);
    dy=0;
    level=1;
}

Bird::~Bird()
{
    std::cout<<("Bird deleted")<<std::endl;
}

void Bird::resetState()
{
    rect.moveTo(INITIAL_X,INITIAL_Y);
}

void Bird::fly()
{
    dy=5;
    int x=rect.left();
    int y=rect.top()-50;
    if(y<0)
        y=0;
    rect.moveTo(x,y);
}

void Bird::drop()
{
    dy++;
    int x=rect.left();
    int y=rect.top()+0.1*dy*dy;
    rect.moveTo(x,y);
}

QRect Bird::getRect()
{
    return rect;
}

QImage &Bird::getImage()
{
    return image;
}

void Bird::timerEvent(QTimerEvent *)
{
 image.load(dirOfWing[curWing]);
 curWing++;
 if(curWing>=3)
     curWing=0;
}


